package com.xiaomi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaomi.domain.GoodsEntity;
import com.xiaomi.mappers.GoodsMapper;
import com.xiaomi.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public PageInfo<GoodsEntity> findPageGoods(Integer pageNum) {
        //设置分页信息
        PageHelper.startPage(pageNum,5);
        //查询所有记录
        List<GoodsEntity> accounts = goodsMapper.findPageGoods();
        //封装到PageInfo中自动完成分页
        return new PageInfo<>(accounts);
    }

    @Override
    public boolean deleteGoodsById(String[] ids) {
        return goodsMapper.deleteGoodsById(ids)==ids.length?true:false;
    }

    @Override
    public GoodsEntity findGoodsById(String gid) {
        return goodsMapper.findGoodsById(gid);
    }

    @Override
    public Boolean updateGoods(GoodsEntity goods) {
        return goodsMapper.updateGoods(goods) == 1?true:false;
    }

    @Override
    public Boolean addGoods(GoodsEntity goods) {
        return goodsMapper.addGoods(goods) == 1?true:false;

    }

    @Override
    public List<GoodsEntity> findAllGodds() {
        return goodsMapper.findAllGoods();
    }
}
